import type { ProColumns } from '@ant-design/pro-components';
import type { FormInstance } from 'antd';
import type { MutableRefObject } from 'react';
import type { ActionType } from '@ant-design/pro-components';

export interface ExtendedActionType<P, T = any> extends ActionType {
  /** 搜索 */
  onSearch: (values: P) => Promise<void>;
  /** 重置 */
  onReset: () => void;
  /** 重置并搜索 */
  onResetAndSearch: () => void;
  /** 手动触发搜索 */
  search: (values: P) => Promise<void>;
  /** 手动触发重置 */
  reset: () => void;
  /** 手动更新数据源 */
  updateData: (data: T[], total: number) => void;
  /** 手动设置加载状态 */
  setLoading: (loading: boolean) => void;
}

export interface PcPageConfig<T> {
  actionRef?: MutableRefObject<ActionType | undefined>;
  formRef?: MutableRefObject<FormInstance | undefined>;
  formConfig?: any;
  dataSource: T[];
  loading?: boolean;
  pagination: {
    total: number;
    pageSize: number;
    current: number;
    onChange: (page: number, pageSize: number) => void;
  };
  editableKeys: React.Key[];
  setEditableRowKeys: (keys: React.Key[]) => void;
  setTableLoading: (loading: boolean) => void;
  updateDataSource: (data: T[], total: number) => void;
  onSave?: (key: React.Key, row: T) => Promise<boolean>;
  onCancel?: (key: React.Key) => void;
  createRecordTemplate?: () => T;
  pageRef?: React.MutableRefObject<ExtendedActionType<any, T>>;
}

export interface PcPageProps<T, P extends Record<string, any> = Partial<T>> {
  /** 列配置 */
  columns: ProColumns<T>[];
  /** 页面配置 */
  pageConfig: PcPageConfig<T>;
  /** 页面操作引用 */
  pageRef: MutableRefObject<ExtendedActionType<P>>;
  /** 工具栏渲染函数 */
  toolBarRender?: () => React.ReactNode[];
  /** 可编辑配置 */
  editable?: {
    type: 'single' | 'multiple';
    editableKeys: React.Key[];
    actionRender: (row: T, config: any, defaultDom: any) => React.ReactNode[];
    onSave: (key: React.Key, row: T) => Promise<void>;
    onCancel: (key: React.Key) => Promise<void>;
  };
} 